﻿
function insertContent(cnt) {
    tinyMCE.activeEditor.execCommand('mceInsertContent', false, cnt);
}

function PrepareTinyPlugin(images, files, iconlocation, filetxt, imgtxt) {
    tinymce.create('tinymce.plugins.WikiFilePlugin', {
        createControl: function(n, cm) {
            switch (n) {
                case 'insertbutton':
                    var c = cm.createMenuButton('insertbutton', {
                        title: 'Insert Object',
                        image: iconlocation,
                        icons: false
                    });

                    c.onRenderMenu.add(function(c, m) {
                        var sub;
                        var subimg;
                        if (files.length > 0) {
                            sub = m.addMenu({ title: filetxt });
                            for (var i = 0; i < files.length; i++) {
                                sub.add(files[i]);
                            }
                        }

                        if (images.length > 0) {
                            subimg = m.addMenu({ title: imgtxt });
                            for (var i = 0; i < images.length; i++) {
                                subimg.add(images[i]);
                            }
                        }
                    });

                    // Return the new menu button instance
                    return c;
            }

            return null;
        }
    });

// Register plugin with a short name
tinymce.PluginManager.add('wikifile', tinymce.plugins.WikiFilePlugin);    
}
